#include "comm.hpp"

int main()
{
    //创建共享内存
    key_t k = getKey();
    printf("key: 0x%x\n", k);
    int shmid = createShm(k);
    printf("shmid: %d\n", shmid);

    //sleep(3);

    //关联
    char *start = (char*)attachShm(shmid);
    printf("attach success, address start: %p\n", start);

    //使用
    while (true)
    {
        if (strcmp(start, "break") == 0) break;
        printf("client say: %s\n", start);
        sleep(1);
    }

    //去关联
    detachShm(start);
    printf("server: detachShm success!!!\n");

    //sleep(3);

    //删除共享内存
    delShm(shmid);
    printf("server: delShm success!!!\n");

    return 0;
}